<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="connect">连接</button>
    <button id="send" disabled='true'>发送数据</button> <br>
    从服务端接受的数据如下:<br>
    <span id="recv"></span>
    <script>
        var connect = document.querySelector('#connect')
        var send = document.querySelector('#send')
        var recv = document.querySelector('#recv')
        let ws = null
        connect.onclick = function () {
            ws = new WebSocket('ws://localhost:9998')
            ws.onopen = () => {
                console.log('链接服务端成功了...');
                send.disabled = false
            }
            ws.onclose = () => { console.log('链接服务端失败'); send.disabled = true }
            ws.onmessage = (msg) => {
                console.log('接收到从服务端发送过来的数据了');
                console.log(msg);
                recv.innerHTML = msg.data
            }
        }

        send.onclick = function () {
            // 发送给服务器的判断然后返回数据的
            // action: 'getData', // 代表获取图表的数据
            //     socketType: 'trendData', // 获取什么样的数据
            //     chartName: 'trend', // 数据的名字
            //     value: '' //主题切换 

            // action: 'fullScreen',
            //     socketType: 'fullScreen',
            //     chartName: 'trend',
            //     value: true //true 全屏状态
            ws.send(JSON.stringify({
                action: 'themeChange',
                socketType: 'themeChange',
                chartName: '',//主题切换没必要传递
                value: 'chalk' //你要切换到哪一个主题 一个是chalk 
            }))
        }
    </script>
</body>

</html>